#define DEBUG
#include <cstdio>
#include <cmath>

using namespace std;

int f(int x) {
  int t=sqrt(x);
  for (int i=2; i<=t; i++) {
    if (x%i==0) {
      return i;
    }
  }
  return x;
}

int solve1(int n, int p) {
  const int max = 100000;
  static bool book[max+1];
  if (n>max/p-p) {
    return 0;
  }
  n--;
  book[p] = true;
  for (int i=p; i<=max/p; i++) {
    book[i] = f(i)>=p;
    if (book[i]) {
      n--;
      if (!n) {
	return p*i;
      }
    }
  }
  return 0;
}

int solve2(int n, int p) {
  const int max=1000000000, maxn=1000000;
  static bool book[maxn+1];
  static int que[maxn+1];
  if (n>max/p-p) {
    return 0;
  }
  for (int i=p; i<=max/p-p; i++) {
    if (!book[i]) {
      book[i] = f(i)>=p;
    }
    if (book[i]) {
      n--;
      if (!n) {
	return p*i;
      }
      for (int j=1; j<=que[0]; j++) {
	if (que[j]*i<=max/p-p) {
	  book[que[j]*i] = true;
	} else {
	  break;
	}
      }
    }
  }
  return 0;
}

int main() {
#ifdef DEBUG
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  int n, p;
  scanf("%d %d", &n, &p);

  printf("%d", n==1 ? p : (p<=1000 ? solve1(n, p) : solve2(n, p)));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
